gdkproperty-win32.c: Fix gtk-font-name handling
authorChun-wei Fan <fanchunwei@src.gnome.org>
Fri, 14 Mar 2014 08:33:53 +0000 (16:33 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Fri, 28 Mar 2014 13:06:14 +0000 (21:06 +0800)
...on Windows 8+ and when the system setting for non-Unicode programs do
not match the language version of Windows by falling back to using Pango.

This ensures that the correct font is used during these scenarios, so that
we minimize the risk of seeing garbled characters for texts that the system
code page does not support due to system peculiarties.  There might be a
way to support gtk-font-name handling using the native Windows APIs
directly on Windows 8+, but that needs to be investigated.

https://bugzilla.gnome.org/show_bug.cgi?id=726298

gdk/win32/gdkproperty-win32.c

index 2e36b04697a77923abd70e9c836292ba88c285b3..cc0bd25b7cd96250a8d8a628f310f58e20cce719 100644 (file)
@@ -398,6 +398,36 @@ _gdk_win32_screen_get_setting (GdkScreen   *screen,
   else if (strcmp ("gtk-font-name", name) == 0)
     {
       NONCLIENTMETRICS ncm;
+      CPINFOEX cpinfoex_default, cpinfoex_curr_thread;
+      OSVERSIONINFO info;
+      BOOL result_default, result_curr_thread;
+
+      info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+
+      /* TODO: Fallback to using Pango on Windows 8 and later,
+       * as this method of handling gtk-font-name does not work
+       * well there, where garbled text will be displayed for texts
+       * that are not supported by the default menu font.  Look for
+       * whether there is a better solution for this on Windows 8 and
+       * later
+       */
+      if (!GetVersionEx (&info) ||
+          info.dwMajorVersion > 6 ||
+          info.dwMajorVersion == 6 && info.dwMinorVersion >= 2)
+        return FALSE;
+
+      /* check whether the system default ANSI codepage matches the
+       * ANSI code page of the running thread.  If so, continue, otherwise
+       * fall back to using Pango to handle gtk-font-name
+       */
+      result_default = GetCPInfoEx (CP_ACP, 0, &cpinfoex_default);
+      result_curr_thread = GetCPInfoEx (CP_THREAD_ACP, 0, &cpinfoex_curr_thread);
+
+      if (!result_default ||
+          !result_curr_thread ||
+          cpinfoex_default.CodePage != cpinfoex_curr_thread.CodePage)
+        return FALSE;
+
       ncm.cbSize = sizeof(NONCLIENTMETRICS);
       if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, FALSE))
         {